package day19;

public class Demo implements Runnable {
    private volatile int count;

    public void run() {
        for (int i = 1; i <= 100; i++) {
            // 使用 synchronized 关键字确保 count++ 操作的原子性
            synchronized (this) {
                count++;
                System.out.println("购物车：" + count);
            }
        }
    }

    public static void main(String[] args) {
        Demo demo = new Demo();
        for (int i = 1; i <= 1000; i++) {
            new Thread(demo).start();
        }
    }
}
